<?php

class Admin_Index_Controller extends Base_Controller {

  public function action_index()
  {
 
    return View::make('admin/index');
    
  }



  public function action_dele()
  {
    $id = Input::get('id');
    $dele = 0;
    $str = DB::table('member')->where('id','=',$id)->update(array('dele'=>$dele));
    if($str){
        $data = array(
            'code'=>'200',
            'msg'=>'删除成功'
            );
    }else{
        $data = array(
            'code'=>'400',
            'msg'=>'删除失败'
            );
    }
    return json_encode($data);
  }


  public function action_getdata()
  {
    $factorPgData = DB::table('member')
        ->left_join('member_factor','member_factor.mid','=','member.id')
        ->select(array('member.*', 'member_factor.comment'))
        ->where('member.dele','=',1)
        ->paginate(4);

    foreach($factorPgData->results as $k =>$v){
      $factorPgData->results[$k]['subscribe_time']=date('Y-m-d H:i:s',$v['subscribe_time']);
    };
    $res = array(
        'code'=>0,
        'msg'=>'',
        'count'=>$factorPgData->total,
        'data'=>$factorPgData->results,
        );
    return Response::json($res); //把数据转化成json返回
  }


  //查看用户详细信息
  public function action_detail()
  {
    $id = Input::get('id');
    $str = DB::table('member')
            ->left_join('member_factor','member_factor.mid','=','member.id')
            ->select(array('member.*', 'member_factor.comment'))
            ->where('member.id','=',$id)
            ->first();

    return View::make('admin/memberdatil',array('str'=>$str));


  }


  public function action_change()
  { 
    $id = Input::get('id');
    $res = DB::table('member')
            ->left_join('member_factor','member_factor.mid','=','member.id')
            ->select(array('member.*', 'member_factor.comment'))
            ->where('member.id','=',$id)
            ->first();
    return View::make('admin/changemember',array('res'=>$res));
  }
 
  public function action_dochange()
  {
    $id = Input::get('id');
    $openid = Input::get('openid');
    $nickname = Input::get('nickname');
    $realname = Input::get('realname');
    $sex = Input::get('sex');
    $province = Input::get('province');
    $city = Input::get('city');
    $phone = Input::get('phone');
    $birthday = Input::get('birthday');
    $subscribe_time = Input::get('subscribe_time');
    $str = DB::table('member')->where('id','=',$id)->update(array('openid'=>$openid,'nickname'=>$nickname,'realname'=>$realname,'sex'=>$sex,'province'=>$province,'city'=>$city,'phone'=>$phone,'birthday'=>$birthday));
    if($str){
        return View::make('jump/success',array('msg'=>'修改成功,','time'=>1));
    }else{
        
        return View::make('jump/success',array('msg'=>'修改失败','time'=>2));
    }
  }


}